import React, { Component } from 'react'
import { WingBlank, WhiteSpace, Grid, Toast, Card } from 'antd-mobile'
import { getSearchParams } from '../../utils/param'
import getData from '../../server/GetData'
import uuid from '../../server/UUIDUtils'
import './index.css'
// const gridData = [
//     {
//         icon: require('../../assets/imgs/zy-icon.png'),
//         text: '住院问卷',
//         path: '/questInfo',
//         operType: 'zy',
//     }, {
//         icon: require('../../assets/imgs/mz-icon.png'),
//         text: '门诊问卷',
//         path: '/questInfo',
//         operType: 'mz',
//     },
//     {
//         icon: require('../../assets/imgs/zy-icon.png'),
//         text: '急症患者',
//         path: '/questInfo',
//         operType: 'jz',
//     },
//     // {
//     //     icon: require('../../assets/imgs/grid-quest.jpg'),
//     //     text: '科室评价',
//     //     path: '/questInfo',
//     //     operType: 4,
//     // }
// ]

export default class index extends Component {
    constructor(props) {
        super(props)
        this.state = {
            wenjuanList: [],
            gridData: []
        }
    }
    toPage(index) {
        if (this.state.gridData.length) {
            this.props.history.push({
                pathname: '/questInfo',
                search: `?deptType=${this.state.gridData[index].mzZyFlag}&wjId=${this.state.gridData[index].wjId}&wjTitle=${encodeURIComponent(this.state.gridData[index].wjTitle)}`,
            })
        } else {
            Toast.fail('暂无问卷');
        }
    }
    componentDidMount() {
        document.title = '问卷列表'
        Toast.loading('科室数据加载中...', 30, () => { });
        getData({
            data: {
                bizContent: {},
                method: 'getMydQuestion',
                bizId: uuid()
            }
        }).then(res => {
            Toast.hide()
            if (res.rspCode != 200) {
                Toast.info(res.rspMsg, 2);
            } else if (res.bizRspCode != 1) {
                Toast.info(res.bizRpsMsg, 2);
            } else {
                let bizContent = res.bizContent
                let wenjuanList = JSON.parse(bizContent).wenjuanList

                console.log('wenjuanList', wenjuanList)

                let gridData = []
                wenjuanList.forEach(item => {
                    gridData.push({
                        icon: item.mzZyFlag == 'qt' ? require('../../assets/imgs/zy-icon.png') : require('../../assets/imgs/' + item.mzZyFlag + '-icon.png'),
                        text: item.wjTitle,
                        path: '/questInfo',
                        mzZyFlag: item.mzZyFlag,
                        wjId: item.wjId,
                        wjTitle: item.wjTitle
                    })
                })

                this.setState({
                    gridData
                })

                console.log(gridData)
            }
        }).catch(err => {
            Toast.hide()
        })
    }
    isZy(flag) {
        return flag === 'zy'
    }
    render() {
        return (
            <div className="questUser-class clearfix">
                {this.state.gridData.map((item, index) => (
                    <div className="btn fl" key={index}>
                        <div
                            className={["btn-icon", this.isZy(item.mzZyFlag) ? "zy-icon" : "mz-icon"].join(' ')}
                            onClick={(v) => this.toPage(index)}></div>
                        <div className="btn-text">{item.wjTitle}</div>
                    </div>
                ))
                }
            </div>
        )
    }
}
